<template>
  <NvCrud :option :data @refresh="handleRefresh" />
</template>

<script setup lang="tsx">
import type { NvCrudOption } from 'nv-crud'
import { NButton } from 'naive-ui'
import { NvCrud } from 'nv-crud'

const data = Array.from({ length: 3 }, (_, i) => ({
  id: i + 1,
  name: `name${i + 1}`,
  sex: i % 2 === 0 ? '男' : '女',
  age: i + 1,
}))

const option: NvCrudOption = {
  toolbar: {
    render: ({ nodes }) => {
      return [
        nodes.Refresh,
        nodes.Divider,
        nodes.Import,
        nodes.Divider,
        nodes.Export,
        nodes.Divider,
        nodes.ColumnSetting,
        nodes.Divider,
        nodes.Fullscreen,
        () => <NButton>自定义按钮</NButton>,
        NButton,
      ]
    },
  },
  rowActions: false,
  actionbar: false,
  fields: {
    name: { title: '姓名' },
    sex: { title: '性别' },
    age: { title: '年龄' },
  },
}

function handleRefresh(done: () => void) {
  setTimeout(done, 1000)
}
</script>
